package com.wangan.wanganpush.xml;

import com.wangan.wanganpush.model.Chat;

import java.util.List;

public class ChatXml {

    private static String number = "";

    public static String parseXml(List<Chat> urList) {
        if (urList == null || urList.size() == 0) return null;

        try {
            StringBuffer sb = new StringBuffer();
            sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>  <MESSAGE>");
            sb.append("<DATASET name=\"WA_COMMON_010000\">  <DATA>");
            sb.append("<ITEM key=\"H010001\" val=\"" + number + "\"/>");
            sb.append("<ITEM key=\"I010014\" val=\"" + number + "\"/>");
            sb.append("<ITEM key=\"I010031\" val=\"" + number + "\"/>");
            sb.append("<ITEM key=\"I010013\" val=\"" + number + "\"/>");
            sb.append("</DATA> </DATASET> ");

            sb.append("<DATASET name=\"WA_COMMON_010022\">");

            for (int i = 0; i <= urList.size(); i++) {
                Chat userChat = urList.get(i);
                sb.append("<DATA>");
                if (userChat.getSendAccountName() != null) {
                    sb.append("<ITEM key=\"B050004\" val=\"" + userChat.getSendAccountName() + "\"/>");
                }

                if (userChat.getAcceptId() != null) {
                    sb.append("<ITEM key=\"B040003\" val=\"" + userChat.getSendId() + "\"/>");
                }

                if (userChat.getAcceptAccountName() != null) {
                    sb.append("<ITEM key=\"B050009\" val=\"" + userChat.getAcceptAccountName() + "\"/>");
                }

                if (userChat.getAcceptId() != null) {
                    sb.append("<ITEM key=\"H100008\" val=\"" + userChat.getAcceptId() + "\"/>");
                }

                if (userChat.getActionTime() != null) {
                    sb.append("<ITEM key=\"H040008\" val=\"" + userChat.getActionTime() + "\"/>");
                }

                if (userChat.getSendIpAddress() != null) {
                    sb.append("<ITEM key=\"F020004\" val=\"" + userChat.getSendIpAddress() + "\"/>");
                }

                if (userChat.getAcceptIpAddress() != null) {
                    sb.append("<ITEM key=\"F020005\" val=\"" + userChat.getAcceptIpAddress() + "\"/>");
                }

                if (userChat.getSendPort() != null) {
                    sb.append("<ITEM key=\"F020006\" val=\"" + userChat.getSendPort() + "\"/>");
                }

                if (userChat.getAcceptPort() != null) {
                    sb.append("<ITEM key=\"F020007\" val=\"" + userChat.getAcceptPort() + "\"/>");
                }

                if (userChat.getSendMacAddress() != null) {
                    sb.append("<ITEM key=\"C040002\" val=\"" + userChat.getSendMacAddress() + "\"/>");
                }

                if (userChat.getAcceptMacAddress() != null) {
                    sb.append("<ITEM key=\"X900013\" val=\"" + userChat.getAcceptMacAddress() + "\"/>");
                }

                if (userChat.getSendTerminalImel() != null) {
                    sb.append("<ITEM key=\"C050001\" val=\"" + userChat.getSendTerminalImel() + "\"/>");
                }

                if (userChat.getAcceptTerminalImel() != null) {
                    sb.append("<ITEM key=\"X900014\" val=\"" + userChat.getAcceptTerminalImel() + "\"/>");
                }

                if (userChat.getActionType() != null) {
                    sb.append("<ITEM key=\"X900012\" val=\"" + userChat.getActionType() + "\"/>");
                }

                if (userChat.getMessageContentType() != null) {
                    sb.append("<ITEM key=\"H010003\" val=\"" + userChat.getMessageContentType() + "\"/>");
                }

                if (userChat.getChatContent() != null) {
                    sb.append("<ITEM key=\"H040001\" val=\"" + userChat.getChatContent() + "\"/>");
                }

                if (userChat.getChatFileName() != null) {
                    sb.append("<ITEM key=\"H010020\" val=\"" + userChat.getChatFileName() + "\"/>");
                }

                if (userChat.getCallTime() != null) {
                    sb.append("<ITEM key=\"H010030\" val=\"" + userChat.getCallTime() + "\"/>");
                }

                if (userChat.getLongitude() != null) {
                    sb.append("<ITEM key=\"F010010\" val=\"" + userChat.getLongitude() + "\"/>");
                }

                if (userChat.getLatitude() != null) {
                    sb.append("<ITEM key=\"F010011\" val=\"" + userChat.getLatitude() + "\"/>");
                }

                if (userChat.getPositionInformation() != null) {
                    sb.append("<ITEM key=\"I020017\" val=\"" + userChat.getPositionInformation() + "\"/>");
                }
                sb.append("</DATA>");
            }

            sb.append("</DATASET>");
            sb.append("</MESSAGE>");


            return sb.toString();

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
